package com.teach.service.impl;

import com.teach.dao.MedalInfoDAO;
import com.teach.dao.impl.MedalInfoDAOImpl;
import com.teach.dto.MedalDto;
import com.teach.dto.MedalSearch;
import com.teach.dto.PageDTO;
import com.teach.service.MedalService;

import java.util.List;

public class MedalServiceImpl implements MedalService {

  private MedalInfoDAO dao = new MedalInfoDAOImpl();

  @Override
  public List<MedalDto> list(MedalSearch search) {
    try{
      return dao.selectSearch(search);
    }catch (Exception e){
      throw new RuntimeException("获取奖牌列表失败",e);
    }
  }

  @Override
  public PageDTO<MedalDto> page(MedalSearch search) {
    try {
      PageDTO<MedalDto> p = new PageDTO<>(dao.countSearch(search), search.getCurrent(), search.getRowMax());
      search.setCurrent(p.getCurrent());
      p.setList(dao.selectSearch(search));
      return p;
    }catch (Exception e){
      throw new RuntimeException("获取奖牌分页失败",e);
    }
  }
}
